<?php
    // +----------------------------------------------------------------------
    // | Created by PHPstorm: JRKAdmin框架 [ JRKAdmin ]
    // +----------------------------------------------------------------------
    // | Copyright (c) 2019~2022 [LuckyHHY] All rights reserved.
    // +----------------------------------------------------------------------
    // | SiteUrl: http://www.luckyhhy.cn
    // +----------------------------------------------------------------------
    // | Author: LuckyHhy <jackhhy520@qq.com>
    // +----------------------------------------------------------------------
    // | Date: 2020/1/3-15:48
    // +----------------------------------------------------------------------
    // | Description:  
    // +----------------------------------------------------------------------


    namespace app\admin\service;


    use app\admin\model\Menus;

    class MenuService extends BaseService
    {

        protected function initialize()
        {
            parent::initialize(); // TODO: Change the autogenerated stub
            $this->table=DB_PREFIX.'menu';
            $this->model=new Menus();
        }



        /**
         * @param array $where
         * @return array
         * @throws \think\db\exception\DataNotFoundException
         * @throws \think\db\exception\ModelNotFoundException
         * @throws \think\exception\DbException
         * @author: LuckyHhy <jackhhy520@qq.com>
         * @date: 2020/1/3
         * @name: menuList
         * @describe:获取菜单列表
         */
        public static  function menuList($where=[]){
            //排序数字越大越靠前
            $where['status']=1;
            $result=self::where($where)->order("listorder desc")->select()->toArray();
            if (!empty($result)){
                foreach ($result as $k=>$v){
                    if(!empty($v['href'])){
                        $result[$k]['url']=url($v['href']);
                    }
                }
            }
            return $result;
        }


        /**
         * @param array $where
         * @return array|bool
         * @throws \think\db\exception\DataNotFoundException
         * @throws \think\db\exception\ModelNotFoundException
         * @throws \think\exception\DbException
         * @author: LuckyHhy <jackhhy520@qq.com>
         * @date: 2020/1/9
         * @name: getOne
         * @describe: 查询单个数据
         */
        public function getOne($where = [])
        {
            if (empty($where)){
                return false;
            }
            return self::where($where)->find();
        }


    }